<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: page_brand.php 135 2013-09-22 07:30:55Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 135 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:30:55 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

if(isset($_GET['brand'])) {	
	$filterlist = $db->db_query("SELECT DISTINCT
										c.categories_id as id,
										cd.categories_name as name
									FROM
										".TABLE_PRODUCTS." p,
										".TABLE_PRODUCTS_TO_CATEGORIES." p2c,
										".TABLE_CATEGORIES." c,
										".TABLE_CATEGORIES_DESCRIPTION." cd
									WHERE
										p.products_status = '1'
									AND
										p.products_id = p2c.products_id
									AND
										p2c.categories_id = c.categories_id
									AND
										p2c.categories_id = cd.categories_id
									AND
										cd.language_id = '".(int)$_SESSION['languages_id']."'
									AND
										p.brand_id = '".(int)$_GET['brand']."'
									ORDER BY
										cd.categories_name");

} elseif(!empty($current_category_id)) {
	$filterlist = $db->db_query("SELECT DISTINCT
										b.brand_id as id,
										b.brand_name as name
									FROM
										".TABLE_PRODUCTS." p,
										".TABLE_PRODUCTS_TO_CATEGORIES." p2c,
										".TABLE_BRAND." b
									WHERE
										p.products_status = '1'
									AND
										p.brand_id = b.brand_id
									AND
										p.products_id = p2c.products_id
									AND
										p2c.categories_id = '".$current_category_id."'
									ORDER BY
										b.brand_name");
										
} else {
	$filterlist = $db->db_query("SELECT DISTINCT
										b.brand_id as id,
										b.brand_name as name
									FROM
										".TABLE_PRODUCTS." p,
										".TABLE_PRODUCTS_TO_CATEGORIES." p2c,
										".TABLE_BRAND." b
									WHERE
										p.products_status = '1'
									AND
										p.brand_id = b.brand_id
									AND
										p.products_id = p2c.products_id
									ORDER BY
										b.brand_name");
}

if($filterlist->_numOfRows) {
    $brand_dropdown = draw_form('filter', $listing->setExternalLink, 'GET')."\n";
    
    if(MODULE_SEO_URL_INDEX_STATUS == 'True') {
		unset($_GET['cPath']);
		unset($_GET['tag']);
		unset($_GET['keywords']);
	}
		
	reset($_GET);
	while(list($key, $value) = each($_GET)) {
		if($key != 'filter_id') {
			if(is_array($value)) {
				while(list($sub_key, $sub_value) = each($value))
					$brand_dropdown .= draw_hidden_field($key.'[]', $sub_value);
			} elseif(!empty($value))
				$brand_dropdown .= draw_hidden_field($key, $value)."\n";
		}
	}
	if(isset($_GET['brand']))
		$brands = array(array('text' => TEXT_ALL_CATEGORIES));
	else
		$brands = array(array('text' => TEXT_ALL_BRAND));
		
    while(!$filterlist->EOF) {
    	$brands[] = array ('id' => $filterlist->fields['id'], 'text' => $filterlist->fields['name']);
    	$filterlist->MoveNext();
    }

    $brand_dropdown .= draw_pull_down_menu('filter_id', $brands, (isset($_GET['brand']) ? $_GET['brand'] : $_GET['filter_id']), 'onchange="this.form.submit();"')."\n";
    $brand_dropdown .= '</form>'."\n";
    
    $module_smarty->assign('BRAND_DROPDOWN', '<li class="page_brand">'.$brand_dropdown.'</li>');
}
?>